﻿using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Http;
using Microsoft.AspNetCore.Mvc;
using System.Net.Http;
using System.Security.Claims;

namespace Demo.Net.JWT.Controllers
{
    [Route("api/[controller]/[action]")]
    [ApiController]
    [Authorize]

    public class JWTTestController : ControllerBase
    {


        public JWTTestController()
        {
            
        }

        [HttpGet]
        public async Task<IActionResult> Test()
        {
           var userId = User.GetUserId();
            var role = HttpContext.User.FindFirst(ClaimTypes.Role)?.Value;
            var role2 = User.GetUserValue(ClaimTypes.Role);
            var wxname = User.GetUserValue("wxname");
            return Ok(new
            {
                userId, role,  role2, wxname
            });
        }


        [AllowAnonymous]
        [HttpGet]
        public async Task<IActionResult> Test2()
        {
            var userId = User.GetUserId();
            var role = HttpContext.User.FindFirst(ClaimTypes.Role)?.Value;
            var role2 = User.GetUserValue(ClaimTypes.Role);
            var wxname = User.GetUserValue("wxname");
            return Ok(new
            {
                userId,
                role,
                role2,
                wxname
            });
        }
    }
}
